package com.example.demo.kafka;

import com.example.demo.config.CdcConfig;
import com.example.demo.dto.CdcMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.UUID;

@Service
public class CdcMessageProducer {

    @Autowired
    private CdcConfig cdcConfig;

    @Autowired
    private KafkaTemplate<String, HashMap> kafkaTemplate;

    public void sendCdcMessage(HashMap message) {
        // 使用header中的messageId作为key
        kafkaTemplate.send(cdcConfig.getKafkaTopic(), UUID.randomUUID().toString(), message);
    }
}    